package com.david.zhufengfm.tasks;

/**
 * Created by David on 2015/10/20.
 * qq:978944820
 */

import android.os.AsyncTask;

import com.david.zhufengfm.Constants;
import com.david.zhufengfm.client.ClientAPI;
import com.david.zhufengfm.entity.DiscoverCategory;
import com.david.zhufengfm.utils.EntityParseUtil;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * 发现部分分类的数据加载异步任务
 */
public class DiscoverCategoryTask extends BaseTask{

    public DiscoverCategoryTask(TaskCallback callback){
        super(callback);
    }
    @Override
    protected TaskResult doInBackground(String... params) {
        TaskResult ret=new TaskResult();
        //唯一
        ret.action= Constants.TASK_ACTION_DISCOVER_CATEGORIES;
        JSONObject jsonObject = ClientAPI.getDiscoverCategories();
        if (jsonObject != null) {
            try {
                ret.resultCode =
                        jsonObject.getInt("ret");
                //解析Json数据
                ret.data= EntityParseUtil.parseDiscoverCategory(jsonObject);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return ret;
    }

    @Override
    protected void onPostExecute(TaskResult result) {
        super.onPostExecute(result);
    }
}
